//------------Sonic CD Credits Control Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 34: TYPE_CREDITSCONTROL


sub ObjectMain
	switch Object.State
	case 0
		Screen.YOffset=Object.Value2
		TempValue0=256
		TempValue0-=Screen.CenterX
		Screen.XOffset=TempValue0
		Object.DrawOrder=0
		if Object.Value0<8
			Object.Value0++
		else
			Object.Value0=254
			PlayMusic(0)
			Object.State++
		endif
		SetScreenFade(0,0,0,255)
		break
	case 1
		if Object.Value0>0
			SetScreenFade(0,0,0,Object.Value0)
			Object.Value0-=8
		else
			Object.State++
		endif
		break
	case 2
		Object.Value2++
		if KeyDown.ButtonA==1
			Object.Value2++
		endif
		if KeyDown.ButtonC==1
			Object.Value2++
		endif
		TempValue0=Object.Value2
		TempValue0>>=1
		Screen.YOffset=TempValue0
		if Object.Value2>Object.Value3
			Object.State=3
			Object.Value0=0
		endif
		if KeyPress.Start==1
			Object.State=3
			Object.Value0=0
		endif
		if KeyPress.ButtonB==1
			Object.State=3
			Object.Value0=0
		endif
		CheckTouchRect(0,0,Screen.XSize,Screen.YSize)
		if CheckResult>-1
			Object.State=3
			Object.Value0=0
		endif
		break
	case 3
		if Object.Value0<320
			Object.Value0+=8
			Music.Volume-=2
		else
			StopMusic()
			Stage.ActiveList=PRESENTATION_STAGE
			if Options.GameMode!=0
				Stage.ListPos=10
			else
				Stage.ListPos=0
			endif
			LoadStage()
		endif
		TempValue0=Object.Value0
		if TempValue0>255
			TempValue0=255
		endif
		SetScreenFade(0,0,0,TempValue0)
		break

	endswitch
endsub


sub ObjectDraw
	DrawRect(0,0,Screen.XSize,Screen.YSize,0,0,0,255)
endsub


sub ObjectStartup
	SetMusicTrack("JP/Credits.ogg",0,1)//Hybrid
#platform: Standard
	LoadTextFile(MENU_1,"Data/Game/Credits_Console.txt",0)
#endplatform
#platform: Mobile
	LoadTextFile(MENU_1,"Data/Game/Credits_Mobile.txt",0)
#endplatform
	Screen.CameraEnabled=0
	Object[0].Type=TypeName[CreditsControl]
	Object[0].Priority=1
	GetTextInfo(TempValue1,MENU_1,2,0,0)
	ArrayPos0=32
	while Object[ArrayPos0].Type!=TypeName[BlankObject]
		ArrayPos0++
	loop
	TempValue0=0
	TempValue2=16777216
	TempValue3=16777216
	while TempValue0<TempValue1
		GetTextInfo(TempValue4,MENU_1,0,TempValue0,1)
		GetTextInfo(TempValue5,MENU_1,1,TempValue0,0)
		if TempValue5==0
			TempValue3+=1441792
		else
			if TempValue4==48
				ResetObjectEntity(ArrayPos0,TypeName[TextFont1],0,TempValue2,TempValue3)
				Object[ArrayPos0].Value1=TempValue0
				ArrayPos0++
				TempValue3+=1441792
			else
				if TempValue4==49
					ResetObjectEntity(ArrayPos0,TypeName[TextFont2],0,TempValue2,TempValue3)
					Object[ArrayPos0].Value1=TempValue0
					ArrayPos0++
					TempValue3+=917504
				else
					if TempValue4==50
						ResetObjectEntity(ArrayPos0,TypeName[TextFont3],0,TempValue2,TempValue3)
						Object[ArrayPos0].Value1=TempValue0
						ArrayPos0++
						TempValue3+=917504
					endif
				endif
			endif
		endif
		TempValue0++
	loop
	TempValue3-=917504
	Object[0].Value3=TempValue3
	Object[0].Value3>>=15
endsub

sub RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endsub
